package com.training.java.core.collections.car.post15;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class CarTreeSetDemo {

	public static void main(String[] args) {
		/**
		 * The Main purpose this demo is to observe TreeSet To observe how
		 * HashCode compare the equality of 2 objects with different Object
		 * References. To observe how is the out put if equals methods and
		 * HashCode methods overridden. TreeSet Should not take null. TreeSet
		 * maintains the objects in alphabetical order. TreeSet Should not take
		 * Nulls.
		 */

		// Instantiating multiple objects

		Car car1 = new Car("1234", "BMW", "X5");
		Car car2 = new Car("2345", "Ford", "Focus");
		Car car3 = new Car("3456", "Honda", "City");
		// duplicate object with different object reference
		Car car4 = new Car("3456", "Honda", "City");
		// mutable object
		Car car5 = new Car();

		// Creating HashSet
		Set<Car> listOfCars = new TreeSet<Car>();

		// Add Car Objects to the HashSet
		listOfCars.add(car1);
		listOfCars.add(car2);
		listOfCars.add(car3);
		listOfCars.add(car4);// Trying to add duplicate object
		// listOfCars.add(null);//NullPointer exception should raise
		// listOfCars.add(car5);

		// for each loop to iterate

		for (Car aCar : listOfCars)

		{

			// Print the VinNumber, Make, Model of the Cars
			System.out.println("VinNumber of the car : " + aCar.getVinNumber());
			System.out.println("Make of the car :  " + aCar.getMake());
			System.out.println("Model of the Car :" + aCar.getModel());
			System.out.println("***************************");

		}

	}

}
